﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Tokens;
using Prism.Services.Dialogs;
using YJTTool.Core.Global;
using YJTTool.Core.Utilities;
using YJTTool.Core.ViewModels;

namespace YJTTool.Configure.ViewModels
{
    public class CreateScheduledTaskDialogViewModel : DialogBaseViewModel
    {
        private TimerTask timers;

        public TimerTask Timers
        {
            get => timers;
            set
            {
                timers = value;
                RaisePropertyChanged();
            }
        }
        public CreateScheduledTaskDialogViewModel()
        {
            Init();
        }

        protected override void OnDialogOpenedWithParameters(IDialogParameters parameters)
        {

        }

        private void Init()
        {
            Timers = GlobalApp.Instance.TimerTimesList;
        }
        private void Judgment() 
        {
            if (string.IsNullOrEmpty(Timers.TimerName))
            {
                MessageWarning("定时器名称不能为空");
                return;
            }
            if (string.IsNullOrEmpty(Timers.Hour))
            {
                MessageWarning("定时器小时不能为空");
                return;
            }
            if (string.IsNullOrEmpty(Timers.Minute))
            {
                MessageWarning("定时器分钟不能为空");
                return;
            }
            if (string.IsNullOrEmpty(Timers.Second))
            {
                MessageWarning("定时器秒数不能为空");
                return;
            }
            if (string.IsNullOrEmpty(Timers.Repeat))
            {
                MessageWarning("定时器重复次数不能为空");
                return;
            }
            if (string.IsNullOrEmpty(Timers.Interval))
            {
                MessageWarning("定时器间隔时间不能为空");
                return;
            }
            if (string.IsNullOrEmpty(Timers.Message))
            {
                MessageWarning("定时器提示信息不能为空");
                return;
            }
            if (Timers.SelectedDays == null || Timers.SelectedDays.Count == 0)
            {
                MessageWarning("定时器重复天次不能为空");
                return;
            }
        }

        /// <summary>
        /// 取消事件
        /// </summary>
        public override void Cancel()
        {
            base.Cancel();
        }

        /// <summary>
        /// 确认事件
        /// </summary>
        public override void Confirm()
        {
            Judgment();
            var dict = new Dictionary<string, Object>();
            dict["param4"] = Timers;
            base.ConfirmWithParameters(dict);
        }
    }
}
